<template>
	<div class="app-container">
	  <a-title @clickPreview="preview" />
	  <el-form ref="queryForm" :model="queryParams" :inline="true" label-width="68px">
		<el-form-item label="归档文件" prop="archiveFile">
		  <el-input
			v-model="queryParams.name"
			placeholder="请输入归档文件"
			clearable
			size="small"
			style="width: 240px"
			@keyup.enter.native="getList"
		  />
		</el-form-item>
		<el-form-item label="是否必须" prop="isMust">
		  <el-select
			v-model="queryParams.mustFlag"
			placeholder="请选择"
			clearable
			size="small"
			style="width: 240px"
		  >
			<el-option label="是" value="1" />
			<el-option label="否" value="0" />
		  </el-select>
		</el-form-item>
		<el-form-item label="归档形式" prop="shape">
		  <el-input
			v-model="queryParams.shape"
			placeholder="请输入归档形式"
			clearable
			size="small"
			style="width: 240px"
			@keyup.enter.native="getList"
		  />
		</el-form-item>
		<el-form-item>
		  <el-button type="primary" icon="el-icon-search" size="mini" @click="getList">查询</el-button>
		  <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
		</el-form-item>
	  </el-form>
  
	  <el-row :gutter="10" class="mb8">
		<el-col :span="1.5">
		  <el-button
			type="primary"
			icon="el-icon-plus"
			size="mini"
			@click="handleAdd"
			:disabled="editFlag"
		  >新增</el-button>
		</el-col>
		<el-col :span="1.5">
		  <el-button
			type="primary"
			plain
			icon="el-icon-delete"
			size="mini"
			:disabled="multiple"
			@click="handleDelete"
		  >删除</el-button>
		</el-col>
		<el-col :span="1.5" v-if="closureStatus">
		  <el-button
			type="primary"
			plain
			icon="el-icon-files"
			size="mini"
			:disabled="archiveFlag"
			@click="startIns"
		  >归档流程</el-button>
		</el-col>
		<el-col :span="1.5" v-if="closureStatus">
		  <el-button
			type="primary"
			plain
			icon="el-icon-turn-off"
			size="mini"
			:disabled="unlockFlag"
			@click="unlockIns"
		  >解锁流程</el-button>
		</el-col>
		<el-col :span="1.5">
		  <el-button
			type="primary"
			plain
			icon="el-icon-download"
			size="mini"
			@click="handleExport"
		  >导出清单</el-button>
		</el-col>
		<el-col :span="1.5">
		  <el-button
			type="primary"
			plain
			icon="el-icon-download"
			size="mini"
			@click="bathDownload"
		  >批量下载</el-button>
		</el-col>
	  </el-row>
  
	  <div class="tablebox">
		<el-table
		  stripe
		  ref="multipleTable"
		  v-loading="loading"
		  :data="tableData"
		  style="width: 100%;"
		  @selection-change="handleSelectionChange"
		  @sort-change="tableSortChange"
		  :default-sort="{prop: 'createTime', order: 'descending'}"
		>
		  <el-table-column type="selection" width="55" :selectable="selectable" />
		  <el-table-column
			prop="name"
			label="归档文件"
			width="300"
			:sort-orders="['ascending', 'descending']"
			sortable="custom"
		  />
		  <el-table-column prop="mustFlag" label="是否必须" width="100">
			<template slot-scope="scope">
			  <span v-if="scope.row.mustFlag==='0'">否</span>
			  <span v-else>是</span>
			</template>
		  </el-table-column>
		  <el-table-column
			prop="shape"
			label="归档形式"
			width="120"
			:sort-orders="['ascending', 'descending']"
			sortable="custom"
		  />
		  <el-table-column prop="source" label="资料来源" width="100">
			<template slot-scope="scope">
			  <span>{{scope.row.source}}</span>
			  <!-- <span v-if="scope.row.source===0">收资管理</span>
			  <span v-else-if="scope.row.source===1">项目文档</span>
			  <span v-else-if="scope.row.source===2">上传</span>-->
			</template>
		  </el-table-column>
		  <el-table-column prop="attachments" label="附件" width>
			<template slot-scope="scope">
			  <div v-for="item in scope.row.attachments" :key="item.fileId" class="fileTable">
				<el-tooltip class="item" effect="dark" :content="item.fileName" placement="top">
				  <div class="fileTableTr">{{ item.fileName }}</div>
				</el-tooltip>
				<div v-if="item.fileName">
				  <a @click="downloadOne(item.fileId,item.fileName)" class="a-style">下载</a>
				  <!-- <a class="a-style" :href="item.storagePath" :download="item.fileName">下载</a> -->
				  <a class="a-style" @click="handlePreview(item)">预览</a>
				</div>
			  </div>
			</template>
		  </el-table-column>
		  <el-table-column
			prop="remark"
			label="无法归档原因"
			width="150"
			:show-overflow-tooltip="true"
			:sort-orders="['ascending', 'descending']"
			sortable="custom"
		  />
		  <el-table-column width="100" label="操作" v-if="!editFlag">
			<template slot-scope="scope">
			  <a @click="handleEdit(scope.$index, scope.row)">
				<i class="el-icon-edit aicon" />编辑
			  </a>
			</template>
		  </el-table-column>
		</el-table>
		<pagination
		  v-show="total>0"
		  :total="total"
		  :page.sync="queryParams.pageNum"
		  :limit.sync="queryParams.pageSize"
		  @pagination="getList"
		/>
	  </div>
  
	  <el-dialog title="提示" :visible.sync="dialogVisible" width="800px">
		<div slot="title" />
		<div class="tabletitle">
		  <el-row :gutter="20">
			<el-col :span="12">
			  <div class="input-wrap">
				<div class="input-label">归档文件</div>
				<div class="input-content">
				  <el-input v-if="form.mustFlag == '0'" v-model="form.name" placeholder="请输入" />
				  <el-input v-else disabled v-model="form.name" placeholder="请输入" />
				</div>
			  </div>
			</el-col>
			<el-col :span="12">
			  <div class="input-wrap">
				<div class="input-label">归档形式</div>
				<div class="input-content">
				  <el-input v-if="form.mustFlag == '0'" v-model="form.shape" placeholder="请输入" />
				  <el-input v-else disabled v-model="form.shape" placeholder="请输入" />
				</div>
			  </div>
			</el-col>
			<el-col :span="12">
			  <div class="input-wrap">
				<div class="input-label">必须文件</div>
				<div class="input-content" style="margin-top:8px">
				  <el-radio v-model="form.mustFlag" label="1" :disabled="true">是</el-radio>
				  <el-radio v-model="form.mustFlag" label="0" :disabled="true">否</el-radio>
				</div>
			  </div>
			</el-col>
		  </el-row>
		  <el-row>
			<el-col :span="24">
			  <div class="input-wrap">
				<div class="input-label">附件</div>
				<div class="input-content">
				  <vue-uploader
					v-if="open"
					:single-type="false"
					:file-list="form.attachments"
					:data-archive="true"
					@changeFileData="changeFile"
					@removeFileList="removeFileList"
					@getHasFile="getHasFile"
					:pathName="pathName"
				  />
				</div>
			  </div>
			</el-col>
		  </el-row>
		  <el-row>
			<el-col :span="24">
			  <div class="input-wrap">
				<div class="input-label">资料来源</div>
				<div class="input-content">
				  <div style="margin-top:8px">{{ form.source }}</div>
				  <!-- <el-input v-model="form.source" placeholder="请输入" :disabled="true" /> -->
				</div>
			  </div>
			</el-col>
		  </el-row>
		  <el-row v-if="form.mustFlag=='1'">
			<el-col :span="24">
			  <div class="input-wrap">
				<div class="input-label">无法归档原因</div>
				<div class="input-content">
				  <el-input v-model="form.remark" placeholder="请输入" type="textarea" rows="4" />
				</div>
			  </div>
			</el-col>
		  </el-row>
		</div>
		<span slot="footer" class="dialog-footer">
		  <el-button @click="dialogVisible = false">取消</el-button>
		  <el-button type="primary" @click="sumbit">确定</el-button>
		</span>
	  </el-dialog>
	  <el-dialog title="新增" :visible.sync="addVisible" width="40%">
		<el-form ref="addform" :model="addform" :rules="rules" label-width="100px">
		  <!-- <div slot="title" /> -->
		  <el-form-item label="归档文件" prop="name">
			<el-input v-model="addform.name" placeholder="请输入" />
		  </el-form-item>
		  <el-form-item label="归档形式" prop="shape">
			<el-input v-model="addform.shape" placeholder="请输入" />
		  </el-form-item>
		  <!-- <div class="tabletitle">
		  <el-row :gutter="20">
			<el-col :span="24">
			  <div class="input-wrap">
				<div class="input-label">归档文件</div>
				<div class="input-content">
				  <el-input v-model="addform.name" placeholder="请输入" />
				</div>
			  </div>
		  </el-col>-->
		  <!-- <el-col :span="24">
			  <div class="input-wrap">
				<div class="input-label">必须文件</div>
				<div class="input-content" style="margin-top:8px">
				  <el-radio v-model="addform.mustFlag" label="1">是</el-radio>
				  <el-radio v-model="addform.mustFlag" label="0">否</el-radio>
				</div>
			  </div>
		  </el-col>-->
		  <!-- </el-row>
		  </div>-->
		</el-form>
		<span slot="footer" class="dialog-footer">
		  <el-button @click="addVisible = false">取消</el-button>
		  <el-button type="primary" @click="addSumbit" :disabled="canClick">确定</el-button>
		</span>
	  </el-dialog>
	  <el-dialog title="项目文档" :visible.sync="getHasFileVisible" width="1000px">
		<div class="tabletitle">
		  <el-row :gutter="20">
			<el-col :span="8" :xs="24">
			  <el-tree
				:data="treeData"
				node-key="id"
				:expand-on-click-node="false"
				default-expand-all
				@node-click="nodeClick"
			  >
				<span slot-scope="{ node }" class="custom-tree-node">
				  <span :title="node.label">{{ node.label }}</span>
				</span>
			  </el-tree>
			</el-col>
			<el-col :span="8" :xs="24">
			  <el-tree
				:data="treeOneData"
				:props="defaultProps"
				node-key="guid"
				:expand-on-click-node="false"
				@node-click="nodeOneClick"
				:show-checkbox="checkboxFlag"
				@check-change="handleCheckChange"
			  >
				<span slot-scope="{ node }" class="custom-tree-node">
				  <span>{{ node.label }}</span>
				</span>
			  </el-tree>
			</el-col>
			<el-col :span="8" :xs="24">
			  <el-tree
				:data="treeTwoData"
				:props="defaultTwoProps"
				node-key="guid"
				:expand-on-click-node="false"
				show-checkbox
				@check-change="handleCheckChange"
			  >
				<span slot-scope="{ node }" class="custom-tree-node">
				  <span>{{ node.label }}</span>
				</span>
			  </el-tree>
			</el-col>
		  </el-row>
		</div>
		<span slot="footer" class="dialog-footer">
		  <el-button @click="getHasFileVisible = false">取 消</el-button>
		  <el-button type="primary" @click="getHasFileSumbit">确 定</el-button>
		</span>
	  </el-dialog>
	  <!-- 预览 -->
	  <el-dialog :visible.sync="openPreview" width="80%">
		<iframe :src="manualPreviewUrl" frameborder="0" width="100%" height="700px"></iframe>
	  </el-dialog>
	</div>
  </template>
  <script>
  import axios from "axios";
  import aTitle from "@/components/Title";
  import {
	archiveList,
	addarchive,
	delarchive,
	exportArchive,
	archiveInfo,
	archiveUpdate,
	archiveGetpickup,
	archiveGetDoc,
	archiveGetfiles,
	getArchiveAllStatus,
	getDocArchiveByBusinessId,
	listAttachments,
	getReports
  } from "@/api/business/dataArchive";
  
  import vueUploader from "@/components/Uploader";
  import { treeselect1, businessDocListResult } from "@/api/business/projectDoc";
  import { getBpmParams } from "@/api/workflow/workflow";
  import { handleBatchDownload } from "@/api/zipdownload";
  import { checkBusiness } from "@/api/projectWorkbench/projectList/businessManagement"
  import { checkProjectStatus } from "@/api/projectWorkbench/projectGlance";
  import { getCategoryByGuid } from "@/api/system/business_category";
  import { getReportTypeList } from "@/api/projectWorkbench/projectList/reportNo";
  import { checkBmsAgencyNo } from "@/api/projectWorkbench/projectList/agencyNo";
  import { checkBmsCostNo } from "@/api/projectWorkbench/projectList/costNo";
  import { getCostTypeList } from "@/api/projectWorkbench/projectList/costNo";
  export default {
	name: "DataArchive",
	components: { aTitle, vueUploader },
	data() {
	  return {
		closureStatus:false,
		manualPreviewUrl: null,
		openPreview: false,
		open: false,
		pathName: "",
		defaultProps: {
		  children: "children",
		  label: "name",
		},
		defaultTwoProps: {
		  children: "children",
		  label: "fileName",
		},
		checkboxFlag: false,
		titles: [],
		treeData: [],
		treeOneData: [],
		treeTwoData: [],
		getHasFileVisible: false,
		total: 0,
		multiple: true,
		downloadAll: true,
		loading: true,
		dialogVisible: false,
		addVisible: false,
		//归档按钮
		archiveFlag: true,
		//解锁流程
		unlockFlag: true,
		//新增编辑删除按钮
		editFlag: true,
		multipleSelection: [],
		queryParams: {
		  name: undefined,
		  mustFlag: undefined,
		  pageNum: 1,
		  pageSize: 20,
		  businessId: undefined,
		  shape:undefined
		},
		tableData: [],
		form: {},
		addform: {},
		haveFileList: [],
		haveFileListName: [],
		normalizer(node) {
		  return {
			id: node.guid,
			label: node.label,
			children: node.children,
		  };
		},
		//资料来源
		fileSource: [],
		rules: {
		  name: [
			{ required: true, message: "文件名称不能为空", trigger: "blur" },
		  ],
		},
		fileSourceNow: "",
		sourceFlag: true,
		canClick: false,
	  };
	},
	created() {
	  this.queryParams.businessId = this.$route.params.id;
  
	  checkProjectStatus(this.$route.params.projectId).then(res=>{
		if(res.data){
		  this.closureStatus = true;
		}
		
	  });
  
	  this.getList();
	  this.getTreeselect();
	  this.pathName = `TJECdocuments/${this.$route.params.id}/归档补充资料`;
	},
	mounted(){
	  document.title=document.getElementById("businessNameTitle").innerHTML;
	},
	methods: {
	  preview() {
		this.openPreview = true;
		this.manualPreviewUrl = `${this.previewUrl}${encodeURIComponent(
		  `${this.operationManual}业务主页/资料归档.xlsx`
		)}&name=${encodeURIComponent("资料归档.xlsx")}`;
	  },
	  getList() {
		this.loading = true;
		getArchiveAllStatus(this.queryParams.businessId).then((res) => {
		  const data = res.data;
		  if (data.archiveStatus === "0" && data.flag === "1") {
			this.archiveFlag = false;
		  } else {
			this.archiveFlag = true;
		  }
		  if (data.archiveStatus === "1" && data.canEdit === "1") {
			this.unlockFlag = false;
		  } else {
			this.unlockFlag = true;
		  }
		  if (data.archiveStatus === "0") {
			this.editFlag = false;
		  } else {
			this.editFlag = true;
		  }
		});
		archiveList(this.queryParams).then((res) => {
		  if (res.code === 200) {
			this.tableData = res.rows;
			this.total = res.total;
			this.loading = false;
		  }
		});
	  },
	  getTreeselect() {
		const params = { businessId: this.$route.params.id };
		treeselect1(params).then((response) => {
		  this.treeData = response.data;
  
		  this.treeData[0].children = this.treeData[0].children.filter(
			(item) => item.flag != "2"
		  );
		});
	  },
	  nodeClick(data, node) {
		this.treeTwoData = [];
		this.haveFileList = [];
		this.haveFileListName = [];
		if (data.flag === "0") {
		  archiveGetpickup(this.$route.params.id).then((res) => {
			this.treeOneData = res.data;
			this.checkboxFlag = false;
			this.fileSourceNow = "收资管理";
		  });
		} else if (data.flag === "3") {
		  var rParams = {
			catalogId: data.guid,
			businessId: this.$route.params.id,
		  };
		  businessDocListResult(rParams).then((response) => {
			if (response.rows && response.rows[0].attachments) {
			  var attachments = response.rows[0].attachments;
			  attachments.forEach((item) => {
				item.guid = item.fileId;
				item.name = item.fileName;
			  });
			  this.treeOneData = attachments;
			  this.checkboxFlag = true;
			}
			this.fileSourceNow = "成果校审";
		  });
		} else {
		  archiveGetDoc(data.guid).then((res) => {
			this.treeOneData = res.data;
			this.checkboxFlag = false;
			this.fileSourceNow = "项目文档";
		  });
		}
	  },
	  nodeOneClick(data, node) {
		archiveGetfiles(data.guid).then((res) => {
		  this.haveFileListName = [];
		  this.haveFileList = [];
		  this.treeTwoData = res.data;
		});
	  },
	  handleCheckChange(data, checked) {
		if (checked) {
		  this.haveFileList.push(data.guid);
		  this.haveFileListName.push({ guid: data.guid, label: data.fileName });
		  this.form.attachmentVos.push({
			attachmentId: data.guid,
			fileSource: this.fileSourceNow,
		  });
		} else {
		  this.form.attachmentVos = this.form.attachmentVos.filter(
			(item) => item.attachmentId !== data.guid
		  );
		  this.haveFileList = this.haveFileList.filter(
			(item) => item !== data.guid
		  );
		  this.haveFileListName = this.haveFileListName.filter(
			(item) => item.guid !== data.guid
		  );
		}
	  },
	  handleEdit(index, row) {
		archiveInfo(row.guid).then((res) => {
		  if (res.code === 200 && res.data && res.data.attachments) {
			res.data.attachmentIds = [];
			res.data.attachmentVos = [];
			res.data.attachments.forEach((item) => {
			  res.data.attachmentIds.push(item.fileId);
			  res.data.attachmentVos.push({
				attachmentId: item.fileId,
				fileSource: item.fileSource,
			  });
			});
		  }
		  this.form = res.data;
		  // this.getSource()
		  this.dialogVisible = true;
		  this.open = true;
		});
	  },
	  selectable(row, index) {
		if (row.mustFlag === "1") {
		  return false;
		} else {
		  return true;
		}
	  },
	  handleSelectionChange(val) {
		if (!this.editFlag) {
		  this.multiple = !val.length;
		}
		this.downloadAll = !val.length;
		this.multipleSelection = val;
	  },
	  handleExport() {
		exportArchive(this.queryParams).then((res) => {
		  if (res.code === 200) {
			this.download(res.msg);
		  }
		});
	  },
	  handleDelete() {
		// if (this.multipleSelection.some(item => item.mustFlag === '1')) {
		//   this.msgError('只能删除')
		// }
		// this.multipleSelection = this.multipleSelection.filter(item => item.mustFlag === '0')
		const delId = this.multipleSelection.map((item) => item.guid);
		const titles = this.multipleSelection.map((item) => item.name);
		this.$confirm(
		  "是否确定删除归档文件 “" + titles + "” 及其附件？",
		  "提示",
		  {
			confirmButtonText: "确定",
			cancelButtonText: "取消",
			type: "warning",
		  }
		).then(() => {
		  delarchive(delId).then((res) => {
			if (res.code === 200) {
			  this.getList();
			  this.msgSuccess(res.msg);
			}
		  });
		});
	  },
	  handleAdd() {
		this.addVisible = true;
		this.addform = {};
		this.canClick = false;
	  },
	  downloadOne(id, name) {
		this.downloadBlob(id, name);
	  },
	  addSumbit() {
		this.$refs["addform"].validate((valid) => {
		  if (valid) {
			this.addform.businessId = this.$route.params.id;
			this.canClick = true;
			addarchive(this.addform).then((res) => {
			  if (res.code === 200) {
				this.msgSuccess(res.msg);
				this.addVisible = false;
				this.getList();
			  }
			  this.canClick = false;
			});
		  }
		});
	  },
	  sumbit() {
		this.form.attachments = this.form.attachments.filter(
		  (item) => item.id !== undefined
		);
		debugger
		archiveUpdate(this.form).then((res) => {
		  if (res.code === 200) {
			this.msgSuccess(res.msg);
			this.dialogVisible = false;
			this.open = false;
			this.getList();
		  }
		});
	  },
	  resetQuery() {
		this.resetForm("queryParams");
		this.getList();
	  },
	  changeFile(id, name) {
		this.form.attachmentIds.push(id);
		this.form.attachmentVos.push({
		  attachmentId: id,
		  fileSource: "本地上传",
		});
		// this.form.source = '本地上传'
		this.getSource();
		// this.$set(this.form.attachments, this.form.attachments.length, { fileName: name, fileId: id })
	  },
	  removeFileList(id) {
		this.form.attachmentIds = this.form.attachmentIds.filter(
		  (item) => item != id
		);
		this.form.attachments = this.form.attachments.filter(
		  (item) => item.fileId != id
		);
		this.form.attachmentVos = this.form.attachmentVos.filter(
		  (item) => item.attachmentId !== id
		);
		this.getSource();
	  },
	  getHasFile() {
		this.fileSourceNow = "";
		this.haveFileList = [];
		this.treeOneData = [];
		this.treeTwoData = [];
		this.getHasFileVisible = true;
	  },
	  getHasFileSumbit() {
		if (this.form.attachmentIds.length) {
		  this.haveFileListName.map((obj) => {
			this.form.attachmentIds.map((item) => {
			  if (obj.guid === item) {
				this.msgError(obj.label + "已上传");
				// this.sourceFlag = false
			  } else {
			  }
			});
		  });
  
		  this.haveFileListName = this.haveFileListName.map((obj) => {
			return {
			  fileId: obj.guid,
			  fileName: obj.label,
			};
		  });
		  this.form.attachments = [
			...this.haveFileListName,
			...this.form.attachments,
		  ];
		  let object = {};
		  this.form.attachments = this.form.attachments.reduce((item, next) => {
			object[next.fileId]
			  ? ""
			  : (object[next.fileId] = true && item.push(next));
			return item;
		  }, []);
		  // ids 数组去重
		  this.form.attachmentIds = Array.from(
			new Set([...this.form.attachmentIds, ...this.haveFileList])
		  );
		  // console.log(this.form.attachmentIds,'ids')
		} else {
		  //第一次上传
		  this.haveFileList.map((item) => {
			this.form.attachmentIds.push(item);
		  });
		  this.haveFileListName.map((item) => {
			this.form.attachments.push({
			  fileId: item.guid,
			  fileName: item.label,
			});
		  });
		}
  
		// this.form.attachmentIds.map(item => {
		//   this.haveFileListName.map(obj => {
		//     if (item === obj.guid) {
		//       this.msgError(obj.label + "已上传")
		//       this.sourceFlag = false
		//     }
		//     else {
		//       console.log(this.haveFileListName, 'FileListName')
		//       console.log(this.form.attachments, 'attachments')
		//       this.haveFileList.map(item => {
		//         this.form.attachmentIds.push(item)
		//       })
		//       this.haveFileListName.map(item => {
		//         this.form.attachments.push({ fileId: item.guid, fileName: item.label })
		//       })
		//       this.sourceFlag = true
		//     }
		//   })
		// })
		// if (!this.sourceFlag) {
		//   return false
		// }
		// this.haveFileList.map(item => {
		//   this.form.attachmentIds.push(item)
		// })
		// this.haveFileListName.map(item => {
		//   this.form.attachments.push({ fileId: item.guid, fileName: item.label })
		// })
		this.getSource();
		this.getHasFileVisible = false;
		// this.open = false
	  },
	  getSource() {
		this.fileSource = [];
		this.form.attachmentVos.map((item) => {
		  this.fileSource.push(item.fileSource);
		});
		let names = this.fileSource.filter(function (value, index, self) {
		  return self.indexOf(value) === index;
		});
		this.form.source = names.join(",");
		// if (this.fileSource.includes('收资管理') && !this.fileSource.includes('项目文档') && !this.fileSource.includes('本地上传')) {
		//   this.form.source = '收资管理'
		// } else if (this.fileSource.includes('收资管理') && !this.fileSource.includes('项目文档') && this.fileSource.includes('本地上传')) {
		//   this.form.source = '收资管理;本地上传'
		// } else if (!this.fileSource.includes('收资管理') && this.fileSource.includes('项目文档') && !this.fileSource.includes('本地上传')) {
		//   this.form.source = '项目文档'
		// } else if (!this.fileSource.includes('收资管理') && this.fileSource.includes('项目文档') && this.fileSource.includes('本地上传')) {
		//   this.form.source = '项目文档;本地上传'
		// } else if (this.fileSource.includes('收资管理') && this.fileSource.includes('项目文档') && !this.fileSource.includes('本地上传')) {
		//   this.form.source = '项目文档;收资管理'
		// } else if (this.fileSource.includes('收资管理') && this.fileSource.includes('项目文档') && this.fileSource.includes('本地上传')) {
		//   this.form.source = '项目文档;收资管理;本地上传'
		// } else if (!this.fileSource.includes('收资管理') && !this.fileSource.includes('项目文档') && this.fileSource.includes('本地上传')) {
		//   this.form.source = '本地上传'
		// } else if (!this.fileSource.includes('收资管理') && !this.fileSource.includes('项目文档') && !this.fileSource.includes('本地上传')) {
		//   this.form.source = ''
		// }
	  },
	  selectName(node) {
		this.haveFileListName.push({ guid: node.guid, label: node.label });
	  },
	  deselectName(node) {
		this.haveFileListName = this.haveFileListName.filter(
		  (item) => item.guid !== node.guid
		);
	  },
	  handlePreview(row) {
		this.filePreview(row.fileName, row.storagePath);
	  },
	  tableSortChange(column) {
		this.queryParams.pageNum = 1;
  
		if (column.order === "descending") {
		  this.queryParams.sortBy = column.prop;
		  this.queryParams.order = "desc";
		} else {
		  this.queryParams.sortBy = column.prop;
		  this.queryParams.order = "asc";
		}
		this.getList();
	  },
	  startIns() {
		//先判断是否在本业务类别范围内
		checkBusiness(this.$route.params.projectId,this.$route.params.businessCategoryId).then(res=>{
		  if(res.data===1){
			this.startInsSec();
		  }else{
			this.msgError("本项目的服务范围不包含该业务的业务类别，请添加对应的服务范围再发起流程！");
		  }
		});
	  },
	  startInsSec(){
		var params = {
		  businessTypeId: this.$route.params.businessCategoryId,
		  projectId: this.$route.params.projectId,
		  businessId: this.$route.params.id,
		};
		//查询本业务下是否有报告/招标号
		if(this.$route.params.businessCategoryId){
		  getCategoryByGuid(this.$route.params.businessCategoryId).then(res=>{
			if(res.code===200){
			  if(res.data.reportNoApply==="1"){
				//验证是否有咨询报告号
				this.checkReportNo();
			  }else if(res.data.reportNoApply==="2"){
				//验证是否有招标代理号
				this.checkAgencyNo();
			  }else if(res.data.reportNoApply==="3"){
				//验证是否有造价报告号
				this.checkCostNo();
			  }else{
              this.funDocArchiveByBusinessId();
            }
			}
		  });
		}else{
		  this.msgError("请重新刷新页面后再操作！");
		}
	  
		
	  },
	  funDocArchiveByBusinessId(){
		var params = {
			businessTypeId: this.$route.params.businessCategoryId,
			projectId: this.$route.params.projectId,
			businessId: this.$route.params.id,
		};
		getDocArchiveByBusinessId(this.queryParams.businessId).then((res) => {
		  if (res.code === 200 && res.data) {
			this.getBpmParamsFun(params, res.data);
		  }
		});
	  },
	  checkReportNo(){
		  var rParam1 = {
			businessId: this.$route.params.id,
			businessType: this.$route.params.businessCategoryId,
		  };
		  getReportTypeList(rParam1).then((res) => {
			if (res.code === 200) {
			  if (res.data) {
				if (res.data && res.data[0].reportNo && res.data[0].reportType) {
				  this.funDocArchiveByBusinessId();
				} else {
				  this.msgError(
					"本业务暂无咨询报告号，请申请咨询报告号以后再发起归档流程！"
				  );
				  return false;
				}
			  } else {
				this.msgError(
				  "本业务暂无咨询报告号，请申请咨询报告号以后再发起归档流程！"
				);
				return false;
			  }
			}
		  });
	  },
	  checkAgencyNo(){
		var checkParams = {
			businessId: this.$route.params.id,
		  };
		  checkBmsAgencyNo(checkParams).then((res) => {
			if (res.code === 200 && res.data === 0) {
			  this.msgError(
				"本业务暂无招标代理号，请申请招标代理号以后再发起归档流程！"
			  );
			} else {
			  this.funDocArchiveByBusinessId();
			}
		  });
	  },
	  checkCostNo(){
		var rParam1 = {
		  businessId: this.$route.params.id,
		  businessType: this.$route.params.businessCategoryId,
		};
		getCostTypeList(rParam1).then((res) => {
			if (res.code === 200) {
			  if (res.data) {
				  debugger
				if (res.data[0] && res.data[0].costNo && res.data[0].costType) {
				  this.funDocArchiveByBusinessId();
				} else {
				  this.msgError(
					"本业务暂无造价报告号，请申请造价报告号以后再发起归档流程！"
				  );
				  return false;
				}
			  } else {
				this.msgError(
				  "本业务暂无造价报告号，请申请造价报告号以后再发起归档流程！"
				);
				return false;
			  }
			}
		  });
	  },
	  unlockIns() {
		//先判断是否在本业务类别范围内
		checkBusiness(this.$route.params.projectId,this.$route.params.businessCategoryId).then(res=>{
		  if(res.data===1){
			this.unlockInsSec();
		  }else{
			this.msgError("本项目的服务范围不包含该业务的业务类别，请添加对应的服务范围再发起流程！");
		  }
		});
	  },
	  unlockInsSec(){
		var params = {
		  businessTypeId: this.$route.params.businessCategoryId,
		  projectId: this.$route.params.projectId,
		  businessId: this.$route.params.id,
		};
		this.getBpmParamsFun1(params, "");
	  },
	  getBpmParamsFun(params, data) {
  
		getReports(this.$route.params.id).then(res=>{
		  if(res.code===200){
			debugger
			if(res.data && res.data.length>0){
			  if(res.data.length === 1){
				params.reportNo = res.data[0].reportNo;
				params.reportName = res.data[0].reportName;
			  }else{
				const reportNos = [],
					  reportNames = [];
				res.data.map(item=>{
				  reportNos.push(item.reportNo);
				  reportNames.push(item.reportName);
				});
				params.reportNo = reportNos.join(";");
				params.reportName = reportNames.join(";");
			  }
			}
			this.getBpmParamsFunSec(params,data);
		  }
		});
		
	  },
	  getBpmParamsFunSec(params,data){
		debugger
		getBpmParams(params).then((res) => {
		  if (res.code === 200) {
			res.data.reportNo = params.reportNo;
			res.data.reportName = params.reportName;
			this.gotoBpm(res.data, data);
		  }
		});
	  },
	  getBpmParamsFun1(params, data) {
		getBpmParams(params).then((res) => {
		  if (res.code === 200) {
			this.gotoUnlockBpm(res.data, data);
		  }
		});
	  },
	  gotoUnlockBpm(data, dataArchive) {
		var bpmUrl = this.bpmUrl;
		var rParam = {
		  businessCategoryId:
			data.businessCategoryId == null ? "" : data.businessCategoryId,
		  businessCategory:
			data.businessCategory == null ? "" : data.businessCategory,
		  projectId: data.projectId == null ? "" : data.projectId,
		  businessId: data.businessId == null ? "" : data.businessId,
		  businessName: data.businessName == null ? "" : data.businessName,
		  deptId: data.deptId == null ? "" : data.deptId,
		  deptName: data.deptName == null ? "" : data.deptName,
		  projectLeader: data.projectLeader == null ? "" : data.projectLeader,
		  projectLeaderId:
			data.projectLeaderId == null ? "" : data.projectLeaderId,
		  projectName: data.projectName == null ? "" : data.projectName,
		  projectManager: data.projectManager == null ? "" : data.projectManager,
		  projectLeaderNo:
			data.projectLeaderNo == null ? "" : data.projectLeaderNo,
		  projectManagerNo:
			data.projectManagerNo == null ? "" : data.projectManagerNo,
		  projectCode: data.projectCode == null ? "" : data.projectCode,
		  reportName: data.reportName == null ? "" : data.reportName,
		  members: data.members == null ? "" : data.members,
		  referReportName:
			data.referReportName == null ? "" : data.referReportName,
		  reportNo: data.reportNo == null ? "" : data.reportNo,
		  reportId: data.reportId == null ? "" : data.reportId,
		  projectGlobalId:
			data.projectGlobalId == null ? "" : data.projectGlobalId,
		  businessNo: data.businessNo == null ? "" : data.businessNo,
		  agencyId: data.agencyId == null ? "" : data.agencyId,
		  agencyNo: data.agencyNo == null ? "" : data.agencyNo,
		  sectionName: data.sectionName == null ? "" : data.sectionName,
		  agencyName: data.agencyName == null ? "" : data.agencyName,
		  agencyProjectLeaderId: data.agencyProjectLeaderId == null ? "" : data.agencyProjectLeaderId,
        agencyProjectLeader: data.agencyProjectLeader == null ? "" : data.agencyProjectLeader,
        agencyProjectLeaderNo: data.agencyProjectLeaderNo == null ? "" : data.agencyProjectLeaderNo
		};
  
		axios
		  .post(
			bpmUrl + "/Portal/InstanceController/starInstance",
			JSON.stringify(rParam)
		  )
		  .then(function (response) {
			if (response.status == 200 && response.data) {
			  var code = JSON.parse(sessionStorage.getItem("userinfo") || {})
				.jobNo;
			  //code = Encrypt(code);
			  window.open(
				bpmUrl +
				  "/Portal/run.html?workflowCode=projectElectronicUnlock&formId=" +
				  response.data.formId +
				  "&date=" +
				  response.data.date +
				  "&code=" +
				  code,
				"_self"
			  );
			}
		  })
		  .catch(function (error) {
			console.log(error);
		  });
	  },
	  gotoBpm(data, dataArchive) {
		debugger
		var bpmUrl = this.bpmUrl;
		var rParam = {
		  businessCategoryId:
			data.businessCategoryId == null ? "" : data.businessCategoryId,
		  businessCategory:
			data.businessCategory == null ? "" : data.businessCategory,
		  projectId: data.projectId == null ? "" : data.projectId,
		  businessId: data.businessId == null ? "" : data.businessId,
		  businessName: data.businessName == null ? "" : data.businessName,
		  deptId: data.deptId == null ? "" : data.deptId,
		  deptName: data.deptName == null ? "" : data.deptName,
		  projectLeader: data.projectLeader == null ? "" : data.projectLeader,
		  projectLeaderId:
			data.projectLeaderId == null ? "" : data.projectLeaderId,
		  projectName: data.projectName == null ? "" : data.projectName,
		  projectManager: data.projectManager == null ? "" : data.projectManager,
		  projectLeaderNo:
			data.projectLeaderNo == null ? "" : data.projectLeaderNo,
		  projectManagerNo:
			data.projectManagerNo == null ? "" : data.projectManagerNo,
		  projectCode: data.projectCode == null ? "" : data.projectCode,
		  reportName: data.reportName == null ? "" : data.reportName,
		  members: data.members == null ? "" : data.members,
		  referReportName:
			data.referReportName == null ? "" : data.referReportName,
		  reportNo: data.reportNo == null ? "" : data.reportNo,
		  reportId: data.reportId == null ? "" : data.reportId,
		  projectGlobalId:
			data.projectGlobalId == null ? "" : data.projectGlobalId,
  
		  businessNo: data.businessNo == null ? "" : data.businessNo,
		  agencyId: data.agencyId == null ? "" : data.agencyId,
		  agencyNo: data.agencyNo == null ? "" : data.agencyNo,
		  sectionName: data.sectionName == null ? "" : data.sectionName,
		  agencyName: data.agencyName == null ? "" : data.agencyName,
  
		  bizObjectSchemaCode: "projectElectronicArchive",
		  Attachments: dataArchive,
  
		  businessStartTime:data.businessStartTime == null ? "" : data.businessStartTime,
		  businessEndTime:data.businessEndTime == null ? "" : data.businessEndTime,
		  businessStatus:data.businessStatus == null ? "" : data.businessStatus,
		  businessStatusRemark:data.businessStatusRemark == null ? "" : data.businessStatusRemark,
		  agencyProjectLeaderId: data.agencyProjectLeaderId == null ? "" : data.agencyProjectLeaderId,
        agencyProjectLeader: data.agencyProjectLeader == null ? "" : data.agencyProjectLeader,
        agencyProjectLeaderNo: data.agencyProjectLeaderNo == null ? "" : data.agencyProjectLeaderNo
		};
  
		axios
		  .post(
			bpmUrl + "/Portal/InstanceController/starInstance2",
			JSON.stringify(rParam)
		  )
		  .then(function (response) {
			if (response.status == 200 && response.data) {
			  var code = JSON.parse(sessionStorage.getItem("userinfo") || {})
				.jobNo;
			  //code = Encrypt(code);
			  window.open(
				bpmUrl +
				  "/Portal/run.html?workflowCode=projectElectronicArchive&formId=" +
				  response.data.formId +
				  "&date=" +
				  response.data.date +
				  "&code=" +
				  code,
				"_self"
			  );
			}
		  })
		  .catch(function (error) {
			console.log(error);
		  });
	  },
	  bathDownload() {
		listAttachments(this.queryParams).then((res) => {
		  const filesList = [];
		  if (res.code === 200) {
			if (res.data.length > 0) {
			  res.data.forEach((item) => {
				filesList.push({
				  fileurl: "/api/system/download/" + item.fileId,
				  fileName: item.fileName,
				});
			  });
			} else {
			  this.msgError(item.name + "暂无附件！");
			}
			handleBatchDownload(filesList);
		  }
		});
	  },
	},
  };
  </script>
  <style lang="scss" scoped>
  .tabletitle {
	margin: 0 20px;
	.input-wrap {
	  padding: 8px;
	  display: flex;
  
	  .input-label {
		min-width: 1em;
		max-width: 6em;
		color: rgba(0, 0, 0, 0.65);
		margin-right: 8px;
		display: flex;
		margin-top: 10px;
		flex: 0 0 90px;
	  }
  
	  .input-content {
		-webkit-box-flex: 1;
		flex-grow: 1;
		.el-select {
		  width: 100%;
		}
	  }
	}
  }
  .tablebox {
	height: 100%;
  }
  /deep/.el-table .cell {
	font-family: PingFangSC-Regular;
	color: rgba(0, 0, 0, 0.85);
	letter-spacing: 0;
	text-align: center;
	a {
	  font-family: PingFangSC-Regular;
	  font-size: 14px;
	  color: #1890ff;
	  letter-spacing: 0;
	  text-align: right;
	  line-height: 14px;
	  margin: 0 10px;
	}
	.el-date-editor.el-input,
	.el-date-editor.el-input__inner {
	  width: 100%;
	}
  }
  .fileTableTr {
	width: 300px;
  }
  </style>
  